import 'package:flutter/material.dart';

import 'package:get/get.dart';
import '../../../services/screebAdapter.dart';
import 'cartItemNum_view.dart';
import '../controllers/cart_controller.dart';

class CartItemView extends GetView {
  CartController controller = Get.find();
  final Map cartItem;
  CartItemView(this.cartItem, {super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(ScreenAdapter.width(20)),
      decoration: const BoxDecoration(
          color: Colors.white,
          border: Border(bottom: BorderSide(color: Colors.black12, width: 1))),
      child: Row(
        children: [
          // 左侧复选框
          SizedBox(
            width: ScreenAdapter.width(50),
            child: Checkbox(
                activeColor: Colors.red,
                value: cartItem['checked'],
                onChanged: (value) {
                  controller.checkedCartItem(cartItem);
                }),
          ),
          // 中间图片
          Container(
            padding: EdgeInsets.all(ScreenAdapter.width(24)),
            alignment: Alignment.center,
            width: ScreenAdapter.width(260),
            child: Image.network("${cartItem["pic"]}'", fit: BoxFit.fitHeight),
          ),
          // 右侧
          Expanded(
              flex: 1,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '${cartItem["title"]}',
                    style: TextStyle(
                        fontSize: ScreenAdapter.fontSize(36),
                        fontWeight: FontWeight.w200),
                  ),
                  Row(
                    children: [
                      Chip(label: Text('${cartItem["selectedAttr"]}')),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '￥${cartItem["price"]}',
                        style: TextStyle(
                            color: Colors.red,
                            fontSize: ScreenAdapter.fontSize(38)),
                      ),
                      CartItemNum(cartItem)
                    ],
                  )
                ],
              ))
        ],
      ),
    );
  }
}
